blob: 22b919b13bcb673a6c04ea6bad109256aba831ad [file] [log] [blame]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08001Gerrit2 - Installation
2======================
3
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -08004You need a SQL database to house the Gerrit2 metadata. Currently
5PostgreSQL is the only supported database.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08006
7Important Links
8---------------
9
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080010PostgreSQL:
11
12* http://www.postgresql.org/docs/[Documentation]
13
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080014Downloading Gerrit
15------------------
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080016
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080017Current and past binary releases of Gerrit can be obtained from
18the downloads page at the project site:
19
20* http://code.google.com/p/gerrit/downloads/list[Gerrit Downloads]
21
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080022Download any current `*.war` package.
23
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080024
25Building Gerrit From Source
26---------------------------
27
28Alternatively, you can build the application distribution using
29Maven from a source download obtained directly from Git:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080030
31====
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080032 mkdir gerrit2
33 cd gerrit2
34 repo init -u git://android.git.kernel.org/tools/manifest.git
35
36 (cd jgit/jgit-maven/jgit && mvn install)
Shawn O. Pearceb951af12009-02-06 12:32:18 -080037 (cd sshd && mvn install)
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080038
Shawn O. Pearce263786e2009-02-02 15:49:26 -080039 mvn clean package
40 cp target/gerrit-*.war ...YOUR.DEST.../gerrit.war
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080041====
42
43The first build may take a while as dependencies are searched
44for and downloaded from Maven distribution repositories.
45
Shawn O. Pearceb951af12009-02-06 12:32:18 -080046Unfortunately you need to install snapshots of both JGit and
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080047SSHD to your local Maven repository (typically under `~/.m2`).
48These core dependencies are still under active development and have
49not made final releases yet.
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080050
51Apache Maven:
52
53* http://maven.apache.org/download.html[Download]
54* http://maven.apache.org/run-maven/index.html[Running Maven]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080055
Shawn O. Pearceb951af12009-02-06 12:32:18 -080056Apache SSHD:
57
58* http://mina.apache.org/sshd/[Apache SSHD]
59
60
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080061Setting up the Database
62-----------------------
63
64Currently PostgreSQL is the only supported database. H2 may also
65work, but hasn't been tested in a while. The primary concern is
66having support for the database in the gworm project.
67
68PostgreSQL
69~~~~~~~~~~
70
71Create a Gerrit specific user as a normal user (no superuser access)
72and assign it an encrypted password:
73
74====
75 createuser -A -D -P -E gerrit2
76====
77
78Create the database to store the Gerrit metadata, and set the user
79you just created as the owner of that database:
80
81====
82 createdb -E UTF-8 -O gerrit2 reviewdb
83====
84
85Initialize the Schema
86---------------------
87
88Create the Gerrit 2 Tables
89~~~~~~~~~~~~~~~~~~~~~~~~~~
90
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080091Either run CreateSchema from the command line:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080092
93====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080094 java -jar gerrit.war --cat extra/GerritServer.properties_example >GerritServer.properties
95 edit GerritServer.properties
96
97 java -jar gerrit.war CreateSchema
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080098====
99
100Or, run the application once in a container to force it to initialize
101the database schema before accessing it. (See below for deployment
102setup documentation.) If you use this approach, it is recommended
103that you stop the application before continuing with the setup.
104
105Add Indexes
106~~~~~~~~~~~
107
108A script should be run to create the query indexes, so Gerrit
109can avoid table scans when looking up information. Run the
110`sql/query_index.sql` script through your database's query tool.
111
112e.g. with PostgreSQL:
113
114====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800115 java -jar gerrit.war --cat sql/query_index.sql | psql reviewdb
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800116====
117
118Configure site_path
119~~~~~~~~~~~~~~~~~~~
120
121This directory holds server-specific configuration files and
122assets used to customize the deployment. Gerrit needs read
123access (but not write access) to the directory. The path
124is stored in `system_config.site_path`, so you will need to
125update the database with this value.
126
127====
128 mkdir /home/gerrit/cfg
129 cd /home/gerrit/cfg
130
131 ssh-keygen -t rsa -P '' -f ssh_host_rsa_key
132 ssh-keygen -t dsa -P '' -f ssh_host_dsa_key
133
134 psql -c "UPDATE system_config SET site_path='/home/gerrit/cfg'" reviewdb
135====
136
137The SSH keys generated here are used as the host keys for the
138internal SSH daemon run by Gerrit. You may wish to backup these
139key files to ensure they can be restored in the event of a disaster.
140
141The private key files (`ssh_host_rsa_key`, `ssh_host_dsa_key`) should
142be readable *only* by the account that is executing Gerrit2's web
143application container. It is a security risk to make these files
144readable by anyone else.
145
146Create Git Repository Base
147~~~~~~~~~~~~~~~~~~~~~~~~~~
148
149This directory holds the Git repositories that Gerrit knows about
150and can service. Gerrit needs write access to this directory and
151any Git repository stored within it.
152
153====
154 mkdir /srv/git
155 psql -c "UPDATE system_config SET git_base_path='/srv/git'" reviewdb
156====
157
158You may wish to consider also exporting this directory over the
159anonymous git:// protocol, as it is more efficient than Gerrit's
160internal ssh daemon. See the `git-daemon` documentation for details
161on how to configure this if anonymous access is desired.
162
163* http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html[man git-daemon]
164
165Futher Configuration
166~~~~~~~~~~~~~~~~~~~~
167
168Gerrit2 supports some site-specific customizations. These are
169optional and are not required to run a server, but may be desired.
170
Shawn O. Pearcef384b442009-01-10 16:20:56 -0800171* link:config-sso.html[Single Sign-On Systems]
Shawn O. Pearce5a14d662009-01-23 16:39:51 -0800172* link:config-replication.html[Git Replication/Mirroring]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800173* link:config-headerfooter.html[Site Header/Footer]
174* link:config-gitweb.html[Gitweb Integration]
175* link:config-gerrit.html[Other system_config Settings]
176
177Application Deployment
178-----------------------
179
180Jetty
181~~~~~
182
183These directions will configure Gerrit as the default web
184application, allowing URLs like `http://example.com/4543` to
185jump directly to change 4543.
186
187Download and unzip a release version of Jetty. From here on we
188call the unpacked directory `$JETTY_HOME`.
189
190* http://dist.codehaus.org/jetty/[Jetty Downloads]
191
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800192Install the JDBC drivers, using either the ones that come embedded
193with Gerrit, or by downloading them yourself from their mirrors:
194====
195 java -jar gerrit.war --cat lib/c3p0-0.9.1.2.jar >$JETTY_HOME/lib/plus/c3p0-0.9.1.2.jar
196 java -jar gerrit.war --cat lib/postgresql-8.3-603.jdbc3.jar >$JETTY_HOME/lib/plus/postgresql-8.3-603.jdbc3.jar
197====
198
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800199Copy Gerrit into the deployment:
200====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800201 java -jar gerrit.war --cat extra/jetty_gerrit.xml >$JETTY_HOME/contexts/gerrit.xml
202 cp gerrit.war $JETTY_HOME/webapps/gerrit.war
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800203
204 rm -f $JETTY_HOME/context/test.xml
205====
206
207Edit `$JETTY_HOME/contexts/gerrit.xml` to correctly configure the
Shawn O. Pearce92a19d22009-01-13 13:27:59 -0800208database and outgoing SMTP connections, especially the user and
209password fields.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800210
211To start automatically when the system boots, consider a start
212script such as the following in `/etc/init.d/gerrit2-jetty`
213
214====
215 #!/bin/sh
216
217 export JETTY_HOST=127.0.0.1
218 export JETTY_PORT=8081
219 export JETTY_USER=gerrit2
220 export JETTY_PID=/var/run/jetty$JETTY_PORT.pid
221 export JETTY_HOME=/home/$JETTY_USER/jetty
222 export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.07/jre
223
224 JAVA_OPTIONS=""
225 JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.host=$JETTY_HOST"
226 export JAVA_OPTIONS
227
228 exec $JETTY_HOME/bin/jetty.sh "$@"
229====
230
231To deploy on port 80, or to use SSL, you should configure Jetty
232to listen on another port, such as 127.0.0.1:8081 (like the start
233script above does) and then follow the <<apache2,reverse proxy>>
234section below.
235
236[TIP]
237Under Jetty, restarting the web application (e.g. after modifying
238`system_config`) is as simple as touching the config file:
239`$JETTY_HOME/contexts/gerrit.xml`
240
241Other Servlet Containers
242~~~~~~~~~~~~~~~~~~~~~~~~
243
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800244Deploy the `gerrit-*.war` file to your application server as
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800245`gerrit.war`.
246
247Configure the JNDI DataSource `jdbc/ReviewDb` for the Gerrit web
248application context to point to the database you just created.
249Don't forget to ensure your JNDI configuration can load the
250necessary JDBC drivers.
251
Shawn O. Pearce92a19d22009-01-13 13:27:59 -0800252('Optional') Configure the JNDI name `mail/Outgoing` for the web
253application context to be a factory for a `javax.mail.Session`,
254with the connection information necessary to send outgoing emails.
255You may need to download and install the Java Mail JARs in your
256container's classpath. If this is not configured, Gerrit will
257function, but will not be able to send email.
258
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800259[[apache2]]
260Apache2 Reverse Proxy
261~~~~~~~~~~~~~~~~~~~~~
262
263Enable the necessary Apache2 modules:
264
265====
266 a2enmod proxy_http
267 a2enmod disk_cache ; # optional, but helps performance
268====
269
270then setup a VirtualHost to proxy to Gerrit's servlet container,
271setting the `ProxyPass` line to use the port number you configured
272in your servlet container's configuration:
273
274=======================================
275<VirtualHost *>
276 ServerName review.example.com
277#
278 ProxyRequests Off
279 ProxyVia Off
280 ProxyPreserveHost On
281#
282 <Proxy *>
283Order deny,allow
284Allow from all
285 </Proxy>
286 ProxyPass / http://127.0.0.1:8081/
287#
288 <IfModule mod_disk_cache.c>
289CacheEnable disk /
290CacheIgnoreHeaders Set-Cookie
291 </IfModule>
292</VirtualHost>
293=======================================
294
295To enable SSL, see the Apache server documentation.
296
297
298Administrator Setup
299-------------------
300
301Login to Gerrit through the web interface, so that a user account
302is initialized for you.
303
304Add your newly created account to the "Administrators" group,
305so that you can manage the site through the web interface:
306
307====
308 psql reviewdb
309 INSERT INTO account_group_members
310 (account_id, group_id)
311 VALUES (
312 (SELECT account_id FROM accounts
313 WHERE preferred_email='you@example.com'),
314 (SELECT admin_group_id FROM system_config)
315 );
316====
317
318Group memberships are cached, so you need to either restart Gerrit,
319or try flushing the caches over SSH.
320
321Since SSH cache flushing requires being in the "Administrators"
322group you may run into a chicken-and-egg problem, where you cannot
323flush the cache to make yourself an administrator because you are
324not yet an administrator. Therefore, restarting the application
325is the recommended bootstrap technique.
326
327To flush the server's caches over SSH, ensure you have an SSH key
328(you can add one through the web UI under Settings, SSH Keys),
329and then run:
330
331====
332 ssh -p 29418 you@example.com gerrit flush-caches
333====
334
335Project Setup
336-------------
337
338See link:project-setup.html[Project Setup] for further details on
339how to register a project with Gerrit.